import java.util.ArrayList;
import java.util.List;

public class MarketTerminal {
    double[] costOfGoods = {1.25, 4.25, 1, 0.75};
    int numberForDiscountA = 3;
    int numberForDiscountC = 6;
    double priceBundleA = 3;
    double priceBundleC = 5;
    int countA = 0;
    int countB = 0;
    int countC = 0;
    int countD = 0;

    public static void main(String args[]) {
        String value = "ABCD";
        System.out.println("The result is " + calculateTotal(value));
    }

    protected static double calculateTotal(String value) {
        MarketTerminal marketTerminal = new MarketTerminal();
        List<String> getList = marketTerminal.transferStringToList(value);
        double price = marketTerminal.doCountLogic(getList);
        return price;
    }

    protected double doCountLogic(List<String> getList) {
        //            int countA = StringUtils.countMatches(value, "A");
        for (int i = 0; i < getList.size(); i++) {
            String temp = getList.get(i);
            if (temp.equals("A")) {
                countA++;
            } else if (temp.equals("B")) {
                countB++;
            } else if (temp.equals("C")) {
                countC++;
            } else if (temp.equals("D")) {
                countD++;
            } else {
                System.out.println("WRONG STUFF");
                System.exit(0);
            }
        }
        return doDiscountLogic(countA, countB, countC, countD);
    }


    protected double doDiscountLogic(int countA, int countB, int countC, int countD) {
            double bundleA = (int) countA / numberForDiscountA;
            countA = countA % numberForDiscountA;
            double bundleC = (int) countC / numberForDiscountC;
            countC = countC % numberForDiscountC;
            return (bundleA * priceBundleA + bundleC * priceBundleC + countA * costOfGoods[0] + countB * costOfGoods[1] + countC * costOfGoods[2] + countD * costOfGoods[3]);
    }

    List<String> transferStringToList(String value) {
        List<String> listValues = new ArrayList<String>();
        for (int i = 0; i < value.length(); i++) {
            listValues.add(i, value.substring(i, i + 1));
        }
        return listValues;
    }
}
